home *** CD-ROM | disk | FTP | other *** search
/ Aminet 1 / Aminet - June 1993 [Walnut Creek].iso / aminet / util / cli / diff_2_2.lha / diff-2.2 / amiga-diff.diffs < prev    next >
Encoding:
Text File  |  1993-04-17  |  26.2 KB  |  1,092 lines

  1. diff -cr ram:diff-2.2/alloca.c dh1:diff-2.2/alloca.c
  2. *** ram:diff-2.2/alloca.c    Tue Dec 01 19:25:52 1992
  3. --- dh1:diff-2.2/alloca.c    Fri Apr 16 13:16:52 1993
  4. ***************
  5. *** 71,76 ****
  6. --- 71,80 ----
  7.       STACK_DIRECTION = 0 => direction of growth unknown
  8.   */
  9.   
  10. + #ifdef AMIGA
  11. + #define    STACK_DIRECTION    -1
  12. + #endif /* AMIGA */
  13.   #ifndef STACK_DIRECTION
  14.   #define    STACK_DIRECTION    0        /* direction unknown */
  15.   #endif
  16. diff -cr ram:diff-2.2/cmp.c dh1:diff-2.2/cmp.c
  17. *** ram:diff-2.2/cmp.c    Wed Jul 08 21:58:06 1992
  18. --- dh1:diff-2.2/cmp.c    Fri Apr 16 13:16:54 1993
  19. ***************
  20. *** 28,33 ****
  21. --- 28,36 ----
  22.   int cmp ();
  23.   void printc ();
  24.   void error ();
  25. + #ifdef AMIGA
  26. + void fake_stat_result ();
  27. + #endif /* AMIGA */
  28.   
  29.   /* Name under which this program was invoked.  */
  30.   char *program_name;
  31. ***************
  32. *** 166,175 ****
  33. --- 169,191 ----
  34.       usage ("at least one filename should be specified");
  35.       }
  36.   
  37. + #ifndef AMIGA
  38.     if (fstat (file1_desc, &stat_buf1) < 0)
  39.       error (2, errno, "%s", file1);
  40.     if (fstat (file2_desc, &stat_buf2) < 0)
  41.       error (2, errno, "%s", file2);
  42. + #else /* AMIGA */
  43. +   if (file1_desc != 0)
  44. +     if (fstat (file1_desc, &stat_buf1) < 0)
  45. +       error (2, errno, "%s", file1);
  46. +   else
  47. +     fake_stat_result (&stat_buf1);
  48. +   if (file2_desc != 0)
  49. +     if (fstat (file2_desc, &stat_buf2) < 0)
  50. +       error (2, errno, "%s", file2);
  51. +   else
  52. +     fake_stat_result (&stat_buf2);
  53. + #endif /* AMIGA */
  54.   
  55.     /* If both the input descriptors are associated with plain files,
  56.        we can make the job simpler in some cases.  */
  57. ***************
  58. *** 185,190 ****
  59. --- 201,207 ----
  60.   
  61.         /* If output is redirected to "/dev/null", we may assume `-s'.  */
  62.   
  63. + #ifndef AMIGA
  64.         if (comparison_type != type_status)
  65.       {
  66.         struct stat sb;
  67. ***************
  68. *** 200,205 ****
  69. --- 217,223 ----
  70.           comparison_type = type_status;
  71.           }
  72.       }
  73. + #endif /* AMIGA */
  74.   
  75.         /* If only a return code is needed, conclude that
  76.        the files differ if they have different sizes.  */
  77. ***************
  78. *** 510,512 ****
  79. --- 528,548 ----
  80.     while (--width > 0)
  81.       putc (' ', fs);
  82.   }
  83. + #ifdef AMIGA
  84. + void fake_stat_result (sbuf)
  85. +      struct stat *sbuf;
  86. + {
  87. +   time_t cur_time;
  88. +   time (&cur_time);
  89. +   sbuf->st_dev = 0;
  90. +   sbuf->st_ino = 0;
  91. +   sbuf->st_mode = S_IREAD;
  92. +   sbuf->st_nlink = 1;
  93. +   sbuf->st_uid = 0;
  94. +   sbuf->st_gid = 0;
  95. +   sbuf->st_size = 0;
  96. +   sbuf->st_ctime = sbuf->st_atime = sbuf->st_mtime = cur_time;
  97. + }
  98. + #endif /* AMIGA */
  99. diff -cr ram:diff-2.2/diff.c dh1:diff-2.2/diff.c
  100. *** ram:diff-2.2/diff.c    Wed Nov 18 17:17:00 1992
  101. --- dh1:diff-2.2/diff.c    Fri Apr 16 13:17:00 1993
  102. ***************
  103. *** 41,46 ****
  104. --- 41,49 ----
  105.   static void add_regexp();
  106.   static void specify_style ();
  107.   static void usage ();
  108. + #ifdef AMIGA
  109. + static int fake_stat_result ();
  110. + #endif /* AMIGA */
  111.   
  112.   /* Nonzero for -r: if comparing two directories,
  113.      compare their common subdirectories recursively.  */
  114. ***************
  115. *** 720,727 ****
  116. --- 723,753 ----
  117.     if (name1 == 0)
  118.       name1 = name0;
  119.   
  120. + #ifndef AMIGA
  121.     inf[0].name = dir0 == 0 ? name0 : concat (dir0, "/", name0);
  122.     inf[1].name = dir1 == 0 ? name1 : concat (dir1, "/", name1);
  123. + #else /* AMIGA */
  124. +   {
  125. +     int len;
  126. +     if (dir0 != 0) len = strlen (dir0);
  127. +     if (dir0 == 0 || len == 0)
  128. +       inf[0].name = name0;
  129. +     else if (dir0[len-1] == ':')
  130. +       inf[0].name = concat (dir0, "", name0);
  131. +     else
  132. +       inf[0].name = concat (dir0, "/", name0);
  133. +   }
  134. +   {
  135. +     int len;
  136. +     if (dir1 != 0) len = strlen (dir1);
  137. +     if (dir1 == 0 || len == 0)
  138. +       inf[1].name = name1;
  139. +     else if (dir1[len-1] == ':')
  140. +       inf[1].name = concat (dir1, "", name1);
  141. +     else
  142. +       inf[1].name = concat (dir1, "/", name1);
  143. +   }
  144. + #endif /* AMIGA */
  145.   
  146.     /* Stat the files.  Record whether they are directories.  */
  147.   
  148. ***************
  149. *** 738,744 ****
  150. --- 764,774 ----
  151.           {
  152.             inf[i].desc = 0;
  153.             inf[i].name = "Standard Input";
  154. + #ifndef AMIGA
  155.             stat_result = fstat (0, &inf[i].stat);
  156. + #else /* AMIGA */
  157. +           stat_result = fake_stat_result (&inf[i].stat);
  158. + #endif /* AMIGA */
  159.           }
  160.         else
  161.           stat_result = stat (inf[i].name, &inf[i].stat);
  162. ***************
  163. *** 763,773 ****
  164. --- 793,821 ----
  165.         /* If one is a directory, and it was specified in the command line,
  166.        use the file in that dir with the other file's basename.  */
  167.   
  168. + #ifndef AMIGA
  169.         int fnm_arg = inf[0].dir_p;
  170.         int dir_arg = 1 - fnm_arg;
  171.         char *p = rindex (inf[fnm_arg].name, '/');
  172.         char *filename = inf[dir_arg].name
  173.       = concat (inf[dir_arg].name,  "/", (p ? p+1 : inf[fnm_arg].name));
  174. + #else /* AMIGA */
  175. +       int fnm_arg, dir_arg;
  176. +       char *p1, *p2, *p;
  177. +       char *filename;
  178. +       fnm_arg = inf[0].dir_p;
  179. +       dir_arg = 1 - fnm_arg;
  180. +       p1 = rindex (inf[fnm_arg].name, '/');
  181. +       p2 = rindex (inf[fnm_arg].name, ':');
  182. +       p = max (p1, p2);
  183. +       if (*(inf[dir_arg].name + strlen (inf[dir_arg].name) - 1) == ':')
  184. +         filename = inf[dir_arg].name
  185. +           = concat (inf[dir_arg].name, "", (p ? p+1 : inf[fnm_arg].name));
  186. +       else
  187. +         filename = inf[dir_arg].name
  188. +           = concat (inf[dir_arg].name, "/", (p ? p+1 : inf[fnm_arg].name));
  189. + #endif /* !AMIGA */
  190.   
  191.         if (inf[fnm_arg].desc == 0)
  192.       fatal ("can't compare - to a directory");
  193. ***************
  194. *** 911,920 ****
  195. --- 959,994 ----
  196.     else
  197.       fflush (stdout);
  198.   
  199. + #ifndef AMIGA
  200.     if (dir0 != 0)
  201.       free (inf[0].name);
  202.     if (dir1 != 0)
  203.       free (inf[1].name);
  204. + #else /* AMIGA */
  205. +   if (dir0 != 0 && strlen(dir0) != 0)
  206. +     free (inf[0].name);
  207. +   if (dir1 != 0 && strlen(dir1) != 0)
  208. +     free (inf[1].name);
  209. + #endif /* !AMIGA */
  210.   
  211.     return val;
  212.   }
  213. + #ifdef AMIGA
  214. + static int fake_stat_result (sbuf)
  215. +      struct stat *sbuf;
  216. + {
  217. +   time_t cur_time;
  218. +   time (&cur_time);
  219. +   sbuf->st_dev = 0;
  220. +   sbuf->st_ino = 0;
  221. +   sbuf->st_mode = S_IREAD;
  222. +   sbuf->st_nlink = 1;
  223. +   sbuf->st_uid = 0;
  224. +   sbuf->st_gid = 0;
  225. +   sbuf->st_size = 0;
  226. +   sbuf->st_ctime = sbuf->st_atime = sbuf->st_mtime = cur_time;
  227. +   return 0;
  228. + }
  229. + #endif /* AMIGA */
  230. diff -cr ram:diff-2.2/diff3.c dh1:diff-2.2/diff3.c
  231. *** ram:diff-2.2/diff3.c    Thu Feb 11 19:48:30 1993
  232. --- dh1:diff-2.2/diff3.c    Fri Apr 16 13:17:07 1993
  233. ***************
  234. *** 28,33 ****
  235. --- 28,43 ----
  236.   #include "getopt.h"
  237.   #include "system.h"
  238.   
  239. + #ifdef AMIGA
  240. + #include <signal.h>
  241. + #include <exec/types.h>
  242. + #include <dos/dostags.h>
  243. + #include <proto/dos.h>
  244. + #include <proto/exec.h>
  245. + extern struct DosLibrary *DOSBase;
  246. + #endif /* AMIGA */
  247.   /*
  248.    * Internal data structures and macros for the diff3 program; includes
  249.    * data structures for both diff3 diffs and normal diffs.
  250. ***************
  251. *** 240,245 ****
  252. --- 250,262 ----
  253.     char **file;
  254.     struct stat statb;
  255.   
  256. + #ifdef AMIGA
  257. +   if (DOSBase->dl_lib.lib_Version < 37) {
  258. +     fputs ("Need Amiga OS 2.0 (V.37) to execute.\n", stderr);
  259. +     exit (20);
  260. +   }
  261. + #endif /* AMIGA */
  262.     incompat = 0;
  263.   
  264.     argv0 = argv[0];
  265. ***************
  266. *** 1089,1094 ****
  267. --- 1106,1113 ----
  268.        char *filea, *fileb;
  269.        char **output_placement;
  270.   {
  271. + #ifndef AMIGA
  272.     char *argv[6];
  273.     char **ap;
  274.     int fds[2];
  275. ***************
  276. *** 1132,1137 ****
  277. --- 1151,1226 ----
  278.       perror_with_exit ("fork failed");
  279.   
  280.     close (fds[1]);        /* Prevent erroneous lack of EOF */
  281. + #else /* AMIGA */
  282. +   static char diff_command_line[200];
  283. +   int fds[2];
  284. +   char *diff_result;
  285. +   int current_chunk_size;
  286. +   int bytes;
  287. +   int total;
  288. +   void (*oldsigint)();
  289. +   static long num_invocations = 0;
  290. +   char pipe_name[20];
  291. +   struct Task *Task;
  292. +   struct TagItem STags[5];
  293. +   BPTR StdOutDiff;
  294. +   /* The user should not be able to break the program while the child
  295. +      process is being executed, otherwise the child process will still
  296. +      be writing to the pipe-device until it deadlocks because there is
  297. +      no reader on the other side of the pipe. So prohibit breaking the
  298. +      program until the pipe is closed. */
  299. +   oldsigint = signal (SIGINT, SIG_IGN);
  300. +   /* Construct command line. Enclose filenames in double quotes in
  301. +      case the user specifies files with spaces in their names. */
  302. +   strcpy (diff_command_line, diff_program);
  303. +   if (always_text)
  304. +     strcat (diff_command_line, " -a");
  305. +   strcat (diff_command_line, " --");
  306. +   strcat (diff_command_line, " \"");
  307. +   strcat (diff_command_line, filea);
  308. +   strcat (diff_command_line, "\" \"");
  309. +   strcat (diff_command_line, fileb);
  310. +   strcat (diff_command_line, "\"");
  311. +   /* Construct filename for the pipe to be used */
  312. +   Task = FindTask (NULL);
  313. +   num_invocations++;
  314. +   sprintf (pipe_name, "PIPE:%08lX_%ld", Task, num_invocations);
  315. +   /* Open pipe for child process */
  316. +   StdOutDiff = Open (pipe_name, MODE_NEWFILE);
  317. +   if (!StdOutDiff)
  318. +     perror_with_exit ("pipe failed");
  319. +   /* Child process runs asynchronously with pipe as stdout */
  320. +   STags[0].ti_Tag = SYS_Input;
  321. +   STags[0].ti_Data = NULL;
  322. +   STags[1].ti_Tag = SYS_Output;
  323. +   STags[1].ti_Data = StdOutDiff;
  324. +   STags[2].ti_Tag = SYS_Asynch;
  325. +   STags[2].ti_Data = TRUE;
  326. +   STags[3].ti_Tag = SYS_UserShell;
  327. +   STags[3].ti_Data = TRUE;
  328. +   STags[4].ti_Tag = TAG_DONE;
  329. +   /* Start child process */
  330. +   if ((System (diff_command_line, STags)) != 0) {
  331. +     Close (StdOutDiff);
  332. +     perror_with_exit ("diff: not found");
  333. +   }
  334. +   /* Open pipe for this side of the communication */
  335. +   fds[0] = open (pipe_name, O_RDONLY);
  336. +   if (fds[0] < 0) {
  337. +     Close (StdOutDiff);
  338. +     perror_with_exit ("pipe failed");
  339. +   }
  340. + #endif /* !AMIGA */
  341.     current_chunk_size = DIFF_CHUNK_SIZE;
  342.     diff_result = (char *) xmalloc (current_chunk_size);
  343.     total = 0;
  344. ***************
  345. *** 1149,1154 ****
  346. --- 1238,1244 ----
  347.   
  348.     *output_placement = diff_result;
  349.   
  350. + #ifndef AMIGA
  351.     do
  352.       if ((w = wait (&wstatus)) == -1)
  353.         perror_with_exit ("wait failed");
  354. ***************
  355. *** 1156,1161 ****
  356. --- 1246,1257 ----
  357.   
  358.     if (! (WIFEXITED (wstatus) && WEXITSTATUS (wstatus) < 2))
  359.       fatal ("subsidiary diff failed");
  360. + #else /* AMIGA */
  361. +   /* Close pipe */
  362. +   close (fds[0]);
  363. +   /* Re-install break-handler */
  364. +   signal (SIGINT, oldsigint);
  365. + #endif /* !AMIGA */
  366.   
  367.     return diff_result + total;
  368.   }
  369. diff -cr ram:diff-2.2/fnmatch.c dh1:diff-2.2/fnmatch.c
  370. *** ram:diff-2.2/fnmatch.c    Wed Nov 18 20:24:16 1992
  371. --- dh1:diff-2.2/fnmatch.c    Fri Apr 16 13:17:13 1993
  372. ***************
  373. *** 16,22 ****
  374. --- 16,26 ----
  375.   Cambridge, MA 02139, USA.  */
  376.   
  377.   #include <errno.h>
  378. + #ifndef AMIGA
  379.   #include <fnmatch.h>
  380. + #else /* AMIGA */
  381. + #include "fnmatch.h"
  382. + #endif /* !AMIGA */
  383.   
  384.   #if !defined(__GNU_LIBRARY__) && !defined(STDC_HEADERS)
  385.   extern int errno;
  386. diff -cr ram:diff-2.2/getopt.c dh1:diff-2.2/getopt.c
  387. *** ram:diff-2.2/getopt.c    Mon Jan 18 01:50:26 1993
  388. --- dh1:diff-2.2/getopt.c    Fri Apr 16 13:17:18 1993
  389. ***************
  390. *** 42,50 ****
  391. --- 42,52 ----
  392.   #endif /* alloca.h */
  393.   #endif /* not __GNUC__ */
  394.   
  395. + #ifndef AMIGA
  396.   #if !__STDC__ && !defined(const) && IN_GCC
  397.   #define const
  398.   #endif
  399. + #endif /* !AMIGA */
  400.   
  401.   #include <stdio.h>
  402.   
  403. diff -cr ram:diff-2.2/getopt1.c dh1:diff-2.2/getopt1.c
  404. *** ram:diff-2.2/getopt1.c    Mon Jan 18 01:51:30 1993
  405. --- dh1:diff-2.2/getopt1.c    Fri Apr 16 13:17:23 1993
  406. ***************
  407. *** 21,29 ****
  408. --- 21,31 ----
  409.   
  410.   #include "getopt.h"
  411.   
  412. + #ifndef AMIGA
  413.   #if !__STDC__ && !defined(const) && IN_GCC
  414.   #define const
  415.   #endif
  416. + #endif /* !AMIGA */
  417.   
  418.   #include <stdio.h>
  419.   
  420. diff -cr ram:diff-2.2/sdiff.c dh1:diff-2.2/sdiff.c
  421. *** ram:diff-2.2/sdiff.c    Thu Feb 11 09:39:42 1993
  422. --- dh1:diff-2.2/sdiff.c    Fri Apr 16 13:17:28 1993
  423. ***************
  424. *** 25,30 ****
  425. --- 25,39 ----
  426.   #include <signal.h>
  427.   #include "getopt.h"
  428.   
  429. + #ifdef AMIGA
  430. + #include <exec/types.h>
  431. + #include <dos/dostags.h>
  432. + #include <proto/exec.h>
  433. + #include <proto/dos.h>
  434. + extern struct DosLibrary *DOSBase;
  435. + #endif /* AMIGA */
  436.   #ifndef SEEK_SET
  437.   #define SEEK_SET 0
  438.   #endif
  439. ***************
  440. *** 49,69 ****
  441. --- 58,93 ----
  442.   
  443.   static char *tmpname;
  444.   static int volatile tmpmade;
  445. + #ifndef AMIGA
  446.   static pid_t volatile diffpid;
  447. + #endif /* !AMIGA */
  448.   
  449.   struct line_filter;
  450.   static void diffarg (); /* (char *); */
  451.   static void execdiff (); /* (int, char const *, char const *, char const *); */
  452. + #ifdef AMIGA
  453. + char *xmalloc ();
  454. + static void amiga_exit ();
  455. + static int amiga_break ();
  456. + static void construct_pipe_name ();
  457. + static void construct_command_line ();
  458. + static char command_line[512];
  459. + static FILE *diff_file = NULL;
  460. + static int user_quit = 0;
  461. + #endif /* AMIGA */
  462.   static int edit (); /* (struct line_filter *left, int lenl, struct
  463.                  line_filter *right, int lenr, FILE *outfile); */
  464.   static int interact (); /* (struct line_filter *diff,
  465.                 struct line_filter *left,
  466.                 struct line_filter *right, FILE *outfile); */
  467. + #ifndef AMIGA
  468.   static void trapsigs (); /* (void); */
  469.   /* this lossage until the gnu libc conquers the universe */
  470.   #define TMPNAMSIZE 1024
  471.   #define PVT_tmpdir "/tmp"
  472.   static char *private_tempnam (); /* (const char *, const char *, int, int *); */
  473. + #endif /* !AMIGA */
  474.   static int diraccess ();
  475.   
  476.   /* Options: */
  477. ***************
  478. *** 108,120 ****
  479. --- 132,185 ----
  480.     exit (2);
  481.   }
  482.   
  483. + #ifdef AMIGA
  484. + static void
  485. + amiga_exit ()
  486. + {
  487. +   char *buf;
  488. +   size_t a;
  489. +   if (tmpmade)
  490. +     {
  491. +       remove (tmpname);
  492. +       tmpmade = 0;
  493. +     }
  494. +   if (diff_file)
  495. +     {
  496. +       /* Provide empty pipe! */
  497. +       buf = xmalloc (SDIFF_BUFSIZE);
  498. +       do
  499. +         a = fread (buf, sizeof (char), SDIFF_BUFSIZE, diff_file);
  500. +       while (a == SDIFF_BUFSIZE);
  501. +       fclose (diff_file);
  502. +       diff_file = NULL;
  503. +       free (buf);
  504. +     }
  505. + }
  506. + static int
  507. + amiga_break ()
  508. + {
  509. +   amiga_exit ();
  510. +   return 20;
  511. + }
  512. + #endif /* AMIGA */
  513.   static void
  514.   cleanup ()
  515.   {
  516. + #ifndef AMIGA
  517.     if (0 < diffpid)
  518.       kill (diffpid, SIGPIPE);
  519.     if (tmpmade)
  520.       unlink (tmpname);
  521. + #else /* AMIGA */
  522. +   if (tmpmade)
  523. +     {
  524. +       remove (tmpname);
  525. +       tmpmade = 0;
  526. +     }
  527. + #endif /* !AMIGA */
  528.   }
  529.   
  530.   static void
  531. ***************
  532. *** 230,235 ****
  533. --- 295,301 ----
  534.   }
  535.   #endif
  536.   
  537. + #ifndef AMIGA
  538.   #ifndef HAVE_WAITPID
  539.   /* Emulate waitpid well enough for sdiff, which has at most two children.  */
  540.   static pid_t
  541. ***************
  542. *** 259,264 ****
  543. --- 325,331 ----
  544.     return pid;
  545.   }
  546.   #endif
  547. + #endif /* !AMIGA */
  548.   
  549.   static char const *
  550.   expand_name (name, isdir, other_name)
  551. ***************
  552. *** 273,278 ****
  553. --- 340,346 ----
  554.     else
  555.       {
  556.         /* Yield NAME/BASE, where BASE is OTHER_NAME's basename.  */
  557. + #ifndef AMIGA
  558.         const char
  559.       *p = rindex (other_name, '/'),
  560.       *base = p ? p+1 : other_name;
  561. ***************
  562. *** 282,287 ****
  563. --- 350,381 ----
  564.         r[namelen] = '/';
  565.         bcopy (base, r + namelen + 1, baselen + 1);
  566.         return r;
  567. + #else /* AMIGA */
  568. +       const char *p1, *p2, *base;
  569. +       size_t namelen, baselen;
  570. +       char *r;
  571. +       p1 = rindex (other_name, '/');
  572. +       p2 = rindex (other_name, ':');
  573. +       if (p1 == NULL && p2 == NULL)
  574. +         base = other_name;
  575. +       else
  576. +         base = max (p1 + 1 , p2 + 1);
  577. +       namelen = strlen (name);
  578. +       baselen = strlen (base);
  579. +       r = xmalloc (namelen + baselen + 2);
  580. +       bcopy (name, r, namelen);
  581. +       if (name[namelen-1] != ':')
  582. +         {
  583. +           r[namelen] = '/';
  584. +           bcopy (base, r + namelen + 1, baselen + 1);
  585. +         }
  586. +       else
  587. +         {
  588. +           bcopy (base, r + namelen, baselen + 1);
  589. +         }
  590. +       return r;
  591. + #endif /* AMIGA */
  592.       }
  593.   }
  594.   
  595. ***************
  596. *** 409,414 ****
  597. --- 503,520 ----
  598.     char *editor = getenv ("EDITOR");
  599.     char *differ = getenv ("DIFF");
  600.   
  601. + #ifdef AMIGA
  602. +   if (DOSBase->dl_lib.lib_Version < 37) {
  603. +     fputs ("Need Amiga OS 2.0 (V.37) to execute.\n", stderr);
  604. +     exit (20);
  605. +   }
  606. +   /* Install break and exit traps */
  607. +   if (atexit (&amiga_exit))
  608. +     fatal ("couldn't set exit trap");
  609. +   if (onbreak (&amiga_break))
  610. +     fatal ("couldn't set break trap");
  611. + #endif /* AMIGA */
  612.     prog = argv[0];
  613.     if (editor)
  614.       edbin = editor;
  615. ***************
  616. *** 496,508 ****
  617. --- 602,620 ----
  618.   
  619.     if (! out_file)
  620.       /* easy case: diff does everything for us */
  621. + #ifndef AMIGA
  622.       execdiff (suppress_common_flag, "-y", argv[optind], argv[optind + 1]);
  623. + #else /* AMIGA */
  624. +     execdiff (suppress_common_flag, "-y", argv[optind], argv[optind + 1], FALSE, NULL);
  625. + #endif /* !AMIGA */
  626.     else
  627.       {
  628.         FILE *left, *right, *out, *diffout;
  629.         int diff_fds[2];
  630.         int interact_ok;
  631. + #ifndef AMIGA
  632.         pid_t pid;
  633. + #endif
  634.         struct line_filter lfilt;
  635.         struct line_filter rfilt;
  636.         struct line_filter diff_filt;
  637. ***************
  638. *** 517,522 ****
  639. --- 629,636 ----
  640.         right = ck_fopen (expand_name (argv[optind + 1], rightdir, argv[optind]), "r");
  641.         out = ck_fopen (out_file, "w");
  642.   
  643. + #ifndef AMIGA
  644.         if (pipe (diff_fds))
  645.       perror_fatal ("pipe");
  646.   
  647. ***************
  648. *** 545,562 ****
  649. --- 659,709 ----
  650.         close (diff_fds[1]);
  651.         diffout = ck_fdopen (diff_fds[0], "r");
  652.   
  653. + #else /* AMIGA */
  654. +       {
  655. +         BPTR StdOutDiff;
  656. +         char pipe_name[20];
  657. +         construct_pipe_name (pipe_name);
  658. +         StdOutDiff = Open (pipe_name, MODE_NEWFILE);
  659. +         if (!StdOutDiff)
  660. +           perror_fatal ("pipe");
  661. +         diff_fds[0] = open (pipe_name, O_RDONLY);
  662. +         if (diff_fds[0] == -1)
  663. +           perror_fatal ("pipe");
  664. +         execdiff (0, "--sdiff-merge-assist", argv[optind], argv[optind + 1], TRUE, StdOutDiff);
  665. +       }
  666. +       diffout = ck_fdopen (diff_fds[0], "r");
  667. +       diff_file = diffout;
  668. + #endif /* !AMIGA */
  669.         lf_init (&diff_filt, diffout);
  670.         lf_init (&lfilt, left);
  671.         lf_init (&rfilt, right);
  672.   
  673.         interact_ok = interact (&diff_filt, &lfilt, &rfilt, out);
  674.   
  675. + #ifndef AMIGA
  676.         ck_fclose (diffout);
  677. + #else /* AMIGA */
  678. +       /* If the user signaled quit, let the exit code clean up the
  679. +          pipe and close the file */
  680. +       if (!user_quit)
  681. +         ck_fclose (diffout);
  682. + #endif /* !AMIGA */
  683.         ck_fclose (left);
  684.         ck_fclose (right);
  685.         ck_fclose (out);
  686.   
  687.         {
  688. + #ifndef AMIGA
  689.       int wstatus;
  690.   
  691.       if (waitpid (pid, &wstatus, 0) < 0)
  692. ***************
  693. *** 576,581 ****
  694. --- 723,742 ----
  695.         fatal ("Subsidiary diff failed");
  696.   
  697.       exit (WEXITSTATUS (wstatus));
  698. + #else /* AMIGA */
  699. +     if (tmpmade)
  700. +       {
  701. +         remove (tmpname);
  702. +         tmpmade = 0;
  703. +       }
  704. +     if (! interact_ok)
  705. +       exit (2);
  706. +         diff_file = NULL;
  707. +         exit (0);
  708. + #endif /* !AMIGA */
  709.         }
  710.       }
  711.     return 0;            /* Fool -Wall . . . */
  712. ***************
  713. *** 604,609 ****
  714. --- 765,772 ----
  715.     diffargv[diffargs++] = a;
  716.   }
  717.   
  718. + #ifndef AMIGA
  719.   static void
  720.   execdiff (differences_only, option, file1, file2)
  721.        int differences_only;
  722. ***************
  723. *** 623,631 ****
  724. --- 786,870 ----
  725.     _exit (2);
  726.   }
  727.   
  728. + #else /* AMIGA */
  729. + static void
  730. + execdiff (differences_only, option, file1, file2, asynch, handle)
  731. +      int differences_only;
  732. +      char *option, *file1, *file2;
  733. +      long asynch;
  734. +      BPTR handle;
  735. + {
  736. +   struct TagItem STags[5];
  737. +   if (differences_only)
  738. +     diffarg ("--suppress-common-lines");
  739. +   diffarg (option);
  740. +   diffarg ("--");
  741. +   diffarg (file1);
  742. +   diffarg (file2);
  743. +   diffarg (0);
  744. +   construct_command_line (diffbin, diffargv, command_line);
  745. +   if (asynch)
  746. +     {
  747. +       STags[0].ti_Tag = SYS_Input;
  748. +       STags[0].ti_Data = NULL;
  749. +       STags[1].ti_Tag = SYS_Output;
  750. +       STags[1].ti_Data = handle;
  751. +       STags[2].ti_Tag = SYS_Asynch;
  752. +       STags[2].ti_Data = TRUE;
  753. +       STags[3].ti_Tag = SYS_UserShell;
  754. +       STags[3].ti_Data = TRUE;
  755. +       STags[4].ti_Tag = TAG_DONE;
  756. +       if (System (command_line, STags) != 0)
  757. +         perror_fatal ("diff not found");
  758. +     }
  759. +   else
  760. +     {
  761. +       STags[0].ti_Tag = SYS_Asynch;
  762. +       STags[0].ti_Data = FALSE;
  763. +       STags[1].ti_Tag = SYS_UserShell;
  764. +       STags[1].ti_Data = TRUE;
  765. +       STags[2].ti_Tag = TAG_DONE;
  766. +       if (System (command_line, STags) != 0)
  767. +         perror_fatal ("diff not found");
  768. +       exit (0);
  769. +     }
  770. + }
  771. + static void
  772. + construct_command_line (binname, argvec, com_line)
  773. +      char *binname, **argvec, *com_line;
  774. + {
  775. +   int i;
  776. +   strcpy (com_line, binname);
  777. +   for (i = 1; argvec[i]; i++)
  778. +     {
  779. +       /* Enclose arguments in quotes */
  780. +       strcat (com_line, " \"");
  781. +       strcat (com_line, argvec[i]);
  782. +       strcat (com_line, "\"");
  783. +     }
  784. + }
  785. + static void
  786. + construct_pipe_name (pipe_name)
  787. +      char *pipe_name;
  788. + {
  789. +   static long invocations = 0;
  790. +   struct Task *Task;
  791. +   Task = FindTask (NULL);
  792. +   sprintf (pipe_name, "PIPE:%08lX_%ld", Task, invocations);
  793. + }
  794. + #endif /* !AMIGA */
  795.   
  796.   
  797.   
  798. + #ifndef AMIGA
  799.   /* Signal handling */
  800.   
  801.   static int volatile ignore_signals;
  802. ***************
  803. *** 670,675 ****
  804. --- 909,915 ----
  805.       if (signal (*p, SIG_IGN) != SIG_IGN  &&  signal (*p, catchsig) != SIG_IGN)
  806.         fatal ("signal error");
  807.   }
  808. + #endif /* !AMIGA */
  809.   
  810.   
  811.   
  812. ***************
  813. *** 796,802 ****
  814. --- 1036,1046 ----
  815.         suppress_common_flag = 0;
  816.         break;
  817.       case 'q':
  818. + #ifdef AMIGA
  819. +           user_quit = 1;
  820. + #endif
  821.         return 0;
  822. + #ifndef AMIGA
  823.       case 'e':
  824.         if (! tmpname && ! (tmpname = private_tempnam (0, "sdiff", 1, 0)))
  825.           perror_fatal ("temporary file name");
  826. ***************
  827. *** 869,874 ****
  828. --- 1113,1172 ----
  829.           }
  830.           return 1;
  831.         }
  832. + #else /* AMIGA */
  833. +     case 'e':
  834. +           if (! tmpname && ! (tmpname = tmpnam (NULL)))
  835. +         perror_fatal ("temporary file name");
  836. +       tmpmade = 1;
  837. +       {
  838. +         FILE *tmp;
  839. +             tmp = ck_fopen (tmpname, "w");
  840. +         if (cmd1 == 'l' || cmd1 == 'b')
  841. +           lf_copy (left, lenl, tmp);
  842. +         else
  843. +           lf_skip (left, lenl);
  844. +         if (cmd1 == 'r' || cmd1 == 'b')
  845. +           lf_copy (right, lenr, tmp);
  846. +         else
  847. +           lf_skip (right, lenr);
  848. +         ck_fclose (tmp);
  849. +             {
  850. +               struct TagItem STags[3];
  851. +               sprintf (command_line, "%s \"%s\"", edbin, tmpname);
  852. +               STags[0].ti_Tag = SYS_Asynch;
  853. +               STags[0].ti_Data = FALSE;
  854. +               STags[1].ti_Tag = SYS_UserShell;
  855. +               STags[1].ti_Data = TRUE;
  856. +               STags[2].ti_Tag = TAG_DONE;
  857. +               if (System (command_line, STags) != 0)
  858. +                 perror_fatal ("Subsidiary editor failed");
  859. +         }
  860. +         {
  861. +           static char *buf;
  862. +           size_t size;
  863. +               tmp = ck_fopen (tmpname, "r");
  864. +               buf = xmalloc (SDIFF_BUFSIZE * sizeof (char));
  865. +           while ((size = ck_fread (buf, SDIFF_BUFSIZE, tmp)) != 0)
  866. +         ck_fwrite (buf, size, outfile);
  867. +               free (buf);
  868. +           ck_fclose (tmp);
  869. +         }
  870. +         return 1;
  871. +       }
  872. + #endif /* !AMIGA */
  873.       default:
  874.         give_help ();
  875.         break;
  876. ***************
  877. *** 959,964 ****
  878. --- 1257,1264 ----
  879.     return stat (file, &buf) == 0;
  880.   }
  881.   
  882. + #ifndef AMIGA
  883.   /* These are the characters used in temporary filenames.  */
  884.   static const char letters[] =
  885.     "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789";
  886. ***************
  887. *** 1065,1067 ****
  888. --- 1365,1369 ----
  889.       *lenptr = len;
  890.     return buf;
  891.   }
  892. + #endif /* AMIGA */
  893. diff -cr ram:diff-2.2/system.h dh1:diff-2.2/system.h
  894. *** ram:diff-2.2/system.h    Fri Feb 19 23:32:32 1993
  895. --- dh1:diff-2.2/system.h    Fri Apr 16 13:23:43 1993
  896. ***************
  897. *** 106,114 ****
  898. --- 106,116 ----
  899.   #ifndef rindex
  900.   #define rindex    strrchr
  901.   #endif
  902. + #ifndef AMIGA
  903.   #define bcopy(s,d,n)    memcpy (d,s,n)
  904.   #define bcmp(s1,s2,n)    memcmp (s1,s2,n)
  905.   #define bzero(s,n)    memset (s,0,n)
  906. + #endif /* !AMIGA */
  907.   #else
  908.   #include <strings.h>
  909.   #endif
  910. diff -cr ram:diff-2.2/util.c dh1:diff-2.2/util.c
  911. *** ram:diff-2.2/util.c    Thu Nov 12 17:02:18 1992
  912. --- dh1:diff-2.2/util.c    Fri Apr 16 13:17:43 1993
  913. ***************
  914. *** 19,24 ****
  915. --- 19,35 ----
  916.   
  917.   #include "diff.h"
  918.   
  919. + #ifdef AMIGA
  920. + #include <signal.h>
  921. + #include <exec/types.h>
  922. + #include <dos/dostags.h>
  923. + #include <proto/dos.h>
  924. + #include <proto/exec.h>
  925. + extern struct DosLibrary *DOSBase;
  926. + static char tmpfilename[L_tmpnam];
  927. + #endif /* AMIGA */
  928.   /* Use when a system call returns non-zero status.
  929.      TEXT should normally be the file name.  */
  930.   
  931. ***************
  932. *** 154,159 ****
  933. --- 165,171 ----
  934.     strcat (name, current_name1);
  935.   
  936.     if (paginate_flag)
  937. + #ifndef AMIGA
  938.       {
  939.         int pipes[2];
  940.         int desc;
  941. ***************
  942. *** 187,192 ****
  943. --- 199,224 ----
  944.         outfile = fdopen (pipes[1], "w");
  945.       } 
  946.       }
  947. + #else /* AMIGA */
  948. +     {
  949. +       if (DOSBase->dl_lib.lib_Version < 37)
  950. +     {
  951. +       fputs ("Need Amiga OS 2.0 (V.37) to paginate. ", stderr);
  952. +       fputs ("Using stdout instead.\n", stderr);
  953. +       outfile = stdout;
  954. +     }
  955. +       else
  956. +     {
  957. +       /* Output the differences to a file and process the file with
  958. +        * pr later on. This is a really bad hack (a kluge??? :-) ),
  959. +        * but I couldn't find something better... */
  960. +       tmpnam (tmpfilename);
  961. +       outfile = fopen (tmpfilename, "w");
  962. +       if (outfile == NULL)
  963. +         pfatal_with_name ("pipe");
  964. +     }
  965. +     }
  966. + #endif
  967.     else
  968.       {
  969.   
  970. ***************
  971. *** 225,234 ****
  972. --- 257,308 ----
  973.   finish_output ()
  974.   {
  975.     if (outfile != 0 && outfile != stdout)
  976. + #ifndef AMIGA
  977.       {
  978.         fclose (outfile);
  979.         wait (0);
  980.       }
  981. + #else /* AMIGA */
  982. +     {
  983. +       char *command_line;
  984. +       struct TagItem STags[5];
  985. +       BPTR StdInPr;
  986. +       /* Close the temporary file and run pr with this file as input */
  987. +       fclose (outfile);
  988. +       command_line = (char *) xmalloc (strlen (current_name0)
  989. +                        + strlen (current_name1)
  990. +                        + strlen (switch_string) + 30);
  991. +       strcpy (command_line, "pr -f -h \"");
  992. +       strcat (command_line, "diff");
  993. +       strcat (command_line, switch_string);
  994. +       strcat (command_line, " ");
  995. +       strcat (command_line, current_name0);
  996. +       strcat (command_line, " ");
  997. +       strcat (command_line, current_name1);
  998. +       strcat (command_line, "\"");
  999. +       StdInPr = Open (tmpfilename, MODE_OLDFILE);
  1000. +       if (StdInPr == NULL)
  1001. +     pfatal_with_name ("pipe");
  1002. +       STags[0].ti_Tag = SYS_Input;
  1003. +       STags[0].ti_Data = StdInPr;
  1004. +       STags[1].ti_Tag = SYS_Output;
  1005. +       STags[1].ti_Data = Output ();
  1006. +       STags[2].ti_Tag = SYS_Asynch;
  1007. +       STags[2].ti_Data = FALSE;
  1008. +       STags[3].ti_Tag = SYS_UserShell;
  1009. +       STags[3].ti_Data = TRUE;
  1010. +       STags[4].ti_Tag = TAG_DONE;
  1011. +       if (System (command_line, STags) != 0)
  1012. +     {
  1013. +       Close (StdInPr);
  1014. +       DeleteFile (tmpfilename);
  1015. +       pfatal_with_name ("pr");
  1016. +     }
  1017. +       Close (StdInPr);
  1018. +       DeleteFile (tmpfilename);
  1019. +     }
  1020. + #endif /* !AMIGA */
  1021.   
  1022.     outfile = 0;
  1023.   }
  1024.